<?php

//print_r($_POST);
 
// username and password sent from form 
//print_r($_POST);
$user1=$_POST['user1']; 
$inv_id=$_POST['inv_id'];
$source=$_POST['source'];
$target=$_POST['target'];
$number=$_POST['number'];

$limit= inventory_limit($inv_id);
if(!is_numeric($number)||$number==''){
			header("location:../index.php?page=organization_distribute&id=".$source."&stat=error&error=badData");
	
return;
}
if($limit>=$number){
	$scan_code=inventory_scan_code($inv_id);
	
	echo "limitation passed and scan_code: ".$scan_code."<br>";
	
	//distributeItem($inv_id,$scan_code,$limit,$number,$source,$target,$user1);
	//return;
	
	if(distributeItem($inv_id,$scan_code,$limit,$number,$source,$target,$user1)){
		//return;
	header("location:../index.php?page=organization_distribute&id=".$source."&stat=distributed");
	}else{
		header("location:../index.php?page=organization_distribute&id=".$source."&stat=error&error=badData");
		
	}
	
	
}else{
		header("location:../index.php?page=organization_distribute&id=".$source."&stat=error&error=limit");
	
	
}


?>